import java.util.*;

//class ListNode {
//    int val;
//    ListNode next;
//
//    ListNode(int x) {
//        val = x;
//    }
//}

public class HanXinDianBing {

    public static void sortChunks(int[] arr, int chunkSize) {
        if (arr == null || chunkSize <= 1) return;

        for (int i = 0; i < arr.length; i += chunkSize) {
            int end = arr.length - i;
            if(end < chunkSize) break;
            int[] subArray = Arrays.copyOfRange(arr, i, i + chunkSize);
            Arrays.sort(subArray);
            reverse(subArray, 0, subArray.length-1);

            for (int j = 0; j < subArray.length; j++) {
                arr[i + j] = subArray[j];
            }
        }
    }

    private static void reverse(int[] arr, int start, int end) {
        while (start < end) {
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
    }

    private static int getSize(ListNode start, ListNode end) {
        int size = 0;
        ListNode current = start;
        while (current != end.next) {
            size++;
            current = current.next;
        }
        return size;
    }

    public static void printList(ListNode head) {
        ListNode current = head;
        while (current != null) {
            System.out.print(current.val + " ");
            current = current.next;
        }
        System.out.println();
    }

    public static ListNode buildList(int[] values) {
        if (values == null || values.length == 0) return null;
        ListNode head = new ListNode(values[0]);
        ListNode current = head;
        for (int i = 1; i < values.length; i++) {
            current.next = new ListNode(values[i]);
            current = current.next;
        }
        return head;
    }

    public static int[] parseInput(String input) {
        String trimmed = input.replaceAll("[{}]", "").trim();
        String[] parts = trimmed.split(",");

        int[] values = new int[parts.length];
        for (int i = 0; i < parts.length; i++) {
            values[i] = Integer.parseInt(parts[i].trim());
        }
        return values;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // {6,1,4,3},2
        // {1,3,4},4
        // {1,2,3,4},3
        // {1,2,3,4},1
        String input = scanner.nextLine();

        int[] values = parseInput(input);
        int[] array = Arrays.copyOfRange(values, 0, values.length - 1);
        int len = values[values.length - 1];

        sortChunks(array, len);

        ListNode head = buildList(array);
        printList(head);

        scanner.close();
    }
}
